import { request } from "../request";

const token = localStorage.getItem("token");

/**
 * 添加用户参数接口
 */
export interface AddUserParams {
    id?: number; // pk_id
    username?: string; // 用户名
    password?: string; // 密码
    email?: string; // 邮箱
    avatar?: string; // 头像
    gender?: boolean; // 性别
    role?: string; // 角色
    lastUpdate?: Record<string, unknown>; // 最后更新时间
}

/**
 * 添加用户接口返回结构
 */
export interface AddUserRes {
    code: number;
    message: string;
    data: string;
    timestamp: Record<string, unknown>;
}

/**
 * 添加用户
 * @param params 用户信息
 * @returns 添加结果
 */
export const addUserAPI = async (params: AddUserParams): Promise<AddUserRes> => {
    return request("/api/users", {
        method: "post",
        headers: {
            Authorization: `Bearer ${token}`,
            "Content-Type": "application/json"
        },
        data: JSON.stringify(params)
    });
};